import React, { Component } from 'react';
import BottomBar from 'com/BottomBar'
import ToTop from 'com/ToTop'
import {connect} from 'react-redux'
import {cartGetData} from 'api/cartApi.js'
import {cart_sub_data} from 'store/actionCreator.js'

import CartHeader from 'com/Cart/CartHeader.jsx'
import CartAppend from 'com/Cart/CartAppend.jsx'
import CartList from 'com/Cart/CartList.jsx'
import {CartStyled} from 'styled/Cart/CartStyled.js'




class Cart extends Component {
    constructor(props){
        super(props)
        this.state={
            cartData:[]
        }
    }
    componentWillMount() {
        // 请求数据
        cartGetData().then((ok)=>{
            this.props.dispatch(cart_sub_data(ok))
            this.setState({
                cartData:this.props.state.CR.get("cartData")
            })
            console.log(this.props.state.CR.get("cartData"))
        }).catch((err)=>{
            console.log(err)
        })
    }

    render() {
        return (
            <CartStyled>
                <div className="cartCon">
                    <CartHeader/>
                    <CartAppend/>
                    <CartList/>
                </div>
                <ToTop/>
                <BottomBar/>
            </CartStyled>
        );
    }
}

export default connect((state)=>({state}))(Cart);